package com.zwwang.readconfig.controller;

import com.zwwang.readconfig.controller.query.LoginQuery;
import com.zwwang.readconfig.dto.CountryDto;
import com.zwwang.readconfig.dto.GroupDto;
import com.zwwang.readconfig.dto.StudentDto;
import com.zwwang.readconfig.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@PropertySource(value = "classpath:custom.properties", encoding = "gbk")
public class SomeController
{

    @Value("${city.name}")
    private String city;

    @Autowired
    private StudentDto studentDto;

    @Autowired
    private GroupDto group;


    @Autowired
    private CountryDto countryDto;

    @GetMapping("/some")
    public String someHandle()
    {
        return countryDto.toString();
    }

    @PostMapping(value = "/some_post")
    public String somePostHandle(@RequestBody LoginQuery loginQuery)
    {
        return loginQuery.toString();
    }

    @GetMapping(value = "/login")
    public UserVo login(@RequestParam(value = "userName") String userName,
                        @RequestParam(value = "password") String password)
    {
        UserVo userVo = new UserVo();
        userVo.setUserName(userName);
        userVo.setPassword(password);
        return userVo;
    }

    @GetMapping(value = "/love")
    public String love(@RequestParam(value = "user1") String user1,
                       @RequestParam(value = "user2") String user2)
    {
        return user2 + " I Love You - " + user1;
    }
}
